package day07;

import java.util.Arrays;
import java.util.Scanner;

public class MainTest03 {
    public static void main(String[] args) {
        //菜品信息
        //菜品名字
        String[] dishName = {"红烧带鱼","鱼香肉丝","时令鲜蔬"};
        //菜品价格
        double[] dishPrice = {38,20,10};
        //菜品的点赞
        int[]    dishLove = {0,0,0};
        //订单信息
        //订餐人
        String[] orderNames={};
        //订单上菜品的名字
        String[] orderDishNames={};
        //订单上菜品的单价
        double[] orderDishPrices={};
        //订单上的菜品个数
        int[] orderCounts={};
        //菜品单价*菜品个数 菜品总价
        double[] orderTotalPrices={};
        //送餐时间
        int[] orderDates={};
        //送餐地址
        String[]  orderAddresss={};
        //订单的状态
        int[] orderSates={};

        int choose = 0;
        do{
          System.out.println("欢迎使用“吃货联盟订餐系统”");
          System.out.println("****************************");
          System.out.println("1、我要订餐");
          System.out.println("2、查看餐袋");
          System.out.println("3、签收订单");
          System.out.println("4、删除订单");
          System.out.println("5、我要点赞");
          System.out.println("6、退出系统");
          System.out.println("****************************");
          System.out.println("请选择：");
          Scanner input = new Scanner(System.in);
          choose = input.nextInt();
          //等值判断，判断大3个以上
          switch (choose){
              case 1://1
                  System.out.println("***我要订餐***");
                  //数组扩容
                  orderNames = Arrays.copyOf(orderNames,orderNames.length+1);
                  orderDishNames = Arrays.copyOf(orderDishNames,orderNames.length+1);
                  orderDishPrices = Arrays.copyOf(orderDishPrices,orderNames.length+1);
                  orderCounts = Arrays.copyOf(orderCounts,orderNames.length+1);
                  orderTotalPrices = Arrays.copyOf(orderTotalPrices,orderNames.length+1);
                  orderDates = Arrays.copyOf(orderDates,orderNames.length+1);
                  orderAddresss = Arrays.copyOf(orderAddresss,orderNames.length+1);
                  orderSates = Arrays.copyOf(orderSates,orderNames.length+1);
                  System.out.println("请输入订餐人姓名：");
                 int lastIndex =   orderNames.length-1;
                  orderNames[lastIndex] =  input.next();
                  System.out.println("序号\t   菜名\t 单价 \t点赞");
                  for(int i=0;i<dishName.length;i++){
                      System.out.println((i+1)+"\t"+dishName[i]
                              +"\t"+dishPrice[i]+"\t"+dishLove[i]);
                  }
                  System.out.println("请选择您要点的菜品编号:");
                  int index1 = input.nextInt();
                  orderDishNames[lastIndex] =   dishName[index1-1];
                  orderDishPrices[lastIndex] =   dishPrice[index1-1];
                  System.out.println("请选择您需要的份数:");
                  orderCounts[lastIndex] = input.nextInt();
                  System.out.println("请输入送餐时间（送餐时间是10点至20点间整点送餐）:");
                  orderDates[lastIndex] = input.nextInt();
                  System.out.println("请输入送餐地址：");
                  orderAddresss[lastIndex] = input.next();
                  System.out.println("订餐成功！");
                  System.out.println("您订的是："+orderDishNames[lastIndex]+" "+orderCounts[lastIndex]+"份");
                  System.out.println("送餐时间："+orderDates[lastIndex]+"点");
                  double price = orderDishPrices[lastIndex]*orderCounts[lastIndex];
                  double paotui = price>50?0:5;
                  orderTotalPrices[lastIndex] = price+paotui;
                  System.out.println("餐费："+price+"元，送餐费"+paotui+"元，总计："+orderTotalPrices[lastIndex] +"元。");
                  System.out.println("输入0返回：");
                  choose =  input.nextInt();
                  break;
              case 2:
                  System.out.println("***查看餐袋***");
                  System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
                  for(int i=0;i<orderNames.length;i++){
                      System.out.println((i+1)+"\t"+orderNames[i]+"\t\t"+orderDishNames[i]
                              +"\t"+orderCounts[i]+"\t\t"+orderDates[i]+"\t"+orderAddresss[i]
                              +"\t\t"+orderTotalPrices[i]+"\t"+(orderSates[i]>0?"已完成":"已预定"));
                  }
                  System.out.println("输入0返回：");
                  choose = input.nextInt();
                  break;
              case 3:
                  System.out.println("***签收订单***");
                  System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
                  for(int i=0;i<orderNames.length;i++){
                      System.out.println((i+1)+"\t"+orderNames[i]+"\t\t"+orderDishNames[i]
                              +"\t"+orderCounts[i]+"\t\t"+orderDates[i]+"\t"+orderAddresss[i]
                              +"\t\t"+orderTotalPrices[i]+"\t"+(orderSates[i]>0?"已完成":"已预定"));
                  }
                  System.out.println("请选择要签收的订单序号：");
                  int index3 = input.nextInt();
                  if(orderSates[index3-1]==0){
                      //orderSates[index3-1]=1;
                      System.out.println("订单签收成功！");
                  }else {
                      System.out.println("您选择的订单已完成签收，不能再次签收！");
                  }
                  System.out.println("输入0返回：");
                  choose = input.nextInt();
                  break;
              case 4:
                  System.out.println("***删除订单***");
                  System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
                  for(int i=0;i<orderNames.length;i++){
                      System.out.println((i+1)+"\t"+orderNames[i]+"\t\t"+orderDishNames[i]
                              +"\t"+orderCounts[i]+"\t\t"+orderDates[i]+"\t"+orderAddresss[i]
                              +"\t\t"+orderTotalPrices[i]+"\t"+(orderSates[i]>0?"已完成":"已预定"));
                  }
                  System.out.println("请选择要删除的订单序号：");
                  int index4 = input.nextInt();
                  int start = index4-1;
                  for(int i=start;i<orderNames.length-1;i++){
                      orderNames[i]=orderNames[i+1];//名字
                      orderDishNames[i] =orderDishNames[i+1];
                      orderDishPrices[i] = orderDishPrices[i+1];
                      orderCounts[i] = orderCounts[i+1];
                      orderTotalPrices[i] = orderTotalPrices[i+1];
                      orderDates[i] =orderDates[i+1];
                      orderAddresss[i] = orderAddresss[i+1];
                      orderSates[i] =orderSates[i+1];
                  }
                  orderNames = Arrays.copyOf(orderNames,orderNames.length-1);
                  orderDishNames = Arrays.copyOf(orderDishNames,orderNames.length-1);
                  orderDishPrices = Arrays.copyOf(orderDishPrices,orderNames.length-1);
                  orderCounts = Arrays.copyOf(orderCounts,orderNames.length-1);
                  orderTotalPrices = Arrays.copyOf(orderTotalPrices,orderNames.length-1);
                  orderDates = Arrays.copyOf(orderDates,orderNames.length-1);
                  orderAddresss = Arrays.copyOf(orderAddresss,orderNames.length-1);
                  orderSates = Arrays.copyOf(orderSates,orderNames.length-1);
                  System.out.println("删除订单成功！");
                  System.out.println("输入0返回：");
                  choose = input.nextInt();
                  break;
              case 5:
                  System.out.println("***我要点赞***");
                  System.out.println("序号\t   菜名\t 单价 \t点赞");
                  for(int i=0;i<dishName.length;i++){
                      System.out.println((i+1)+"\t"+dishName[i]
                              +"\t"+dishPrice[i]+"\t"+dishLove[i]);
                  }
                  System.out.println("请输入要点赞的菜品序号：");
                  int index = input.nextInt();
                  //点赞数+1
                  dishLove[index-1] = dishLove[index-1]+1;
                  System.out.println("点赞成功!");
                  System.out.println("输入0返回：");
                  choose = input.nextInt();
                  break;
              case 6:
                  System.out.println("进入菜单6");
                  System.out.println("谢谢使用，欢迎下次光临！");
                  System.exit(0);
                  break;
              default:
                  System.out.println("输入错误，没有这个菜单项");
          }
      }while (choose==0);
    }
}
